<div id="user_introducere_factura"></div>
<script type="text/javascript">
Ext.onReady(function(){
	var fp_user_introducere_factura;
	var grid_user_introducere_factura_articole;
	var ds_articole;
	var cm_articole;
	var cmb_produse;
	var w_user_introducere_factura_previzualizare;
	var w_user_introducere_factura_tiparire;
	var w_user_introducere_factura_client;
	var fp_w_user_introducere_factura_client;


/**
 * stores
 * 
 */

	ds_clienti = new Ext.data.Store({
											     id			:'clienti_ds',
												 baseParams	:{saferequest:true,table:'clienti',cyDep:true,active:true},
											     proxy		:new Ext.data.HttpProxy({
											     				url		:'common/selectTable/' + Math.random()
											     			}),
												 reader		: new Ext.data.JsonReader({
											            		root	:'DS_CLIENTI',
											            		id		:'ID',
											            		fields	:['ID', 'nume']
										         			})
	});
							
	ds_produse = new Ext.data.Store({
											     id			:'produse_ds',
												 baseParams	:{saferequest:true,table:'produse',cyDep:true,active:true},
											     proxy		:new Ext.data.HttpProxy({
											     				url		:'common/selectProduseTable/' + Math.random()
											     			}),
												 reader		: new Ext.data.JsonReader({
											            		root	:'DS_PRODUSE',
											            		id		:'ID',
											            		fields	:['ID', 'value']
										         			})
	});	


	function clienti_add(){
		if (!w_user_introducere_factura_client) {
					// adaugare client form panel	-----------------------------------------------------
					//-----------------------------------------------------------------------------------	
					fp_w_user_introducere_factura_client = new Ext.FormPanel({
							id			:"frm-clienti-add-" + Math.random(),
							monitorValid:true,
							labelAlign	:'top',
							bodyStyle	:'padding:5px',
							border		:false,
							items		:[{
											layout	:'column',
											border	:false,
											items	:[{
									                	columnWidth	:.5,
														defaultType	:'textfield',								
									                	layout		:'form',
									                	border		:false,
														items		:[new Ext.form.ComboBox({
																			anchor		:'90%',	
																			fieldLabel	:'Statut juridic',
																			name		:'n_tip', 
																			allowBlank	:false,
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>', 
																			editable	:false,	
																			allowBlank	:false,							
																			lazyRender	:true,
																			store		:new Ext.data.Store({
																						     id			:'tip_client_ds',
																							 baseParams	:{saferequest:true,code:'client_type'},
																						     proxy		:new Ext.data.HttpProxy({
																						     				url		:'common/getReference/' + Math.random()
																						 }),
																			 reader		: new Ext.data.JsonReader({
																									        root	:'DS_CLIENT_TYPE',
																									        id		:'value',
																									        fields	:['value', 'option']
																				         })
																		}),
																		hiddenName		:'tip',
																		displayField	:'option',
																		valueField		:'value',									
																		triggerAction	:'all',
																		emptyText		:'[Selectati Statutul]',							
																		listeners		: {
																					'select': function(combo, record, index) {
																						if (this.getRawValue() == 'Persoana fizica') {
																							Ext.getCmp('cnp').reset();
																							Ext.getCmp('cnp').enable();
																							Ext.getCmp('persoana-fizica').expand();															
																							Ext.getCmp('cui').reset();
																							Ext.getCmp('cui').disable();
																							Ext.getCmp('nr_reg').reset();
																							Ext.getCmp('nr_reg').disable();		
																							Ext.getCmp('banca').reset();
																							Ext.getCmp('banca').disable();
																							Ext.getCmp('cont').reset();
																							Ext.getCmp('cont').disable();																																						
																							Ext.getCmp('persoana-juridica').collapse();
																						} else if (this.getRawValue() == 'Persoana juridica'){
																							Ext.getCmp('cui').reset();
																							Ext.getCmp('cui').enable();
																							Ext.getCmp('nr_reg').reset();
																							Ext.getCmp('nr_reg').enable();		
																							Ext.getCmp('banca').reset();
																							Ext.getCmp('banca').enable();
																							Ext.getCmp('cont').reset();
																							Ext.getCmp('cont').enable();																																						
																							Ext.getCmp('persoana-juridica').expand();																
																							Ext.getCmp('cnp').reset();
																							Ext.getCmp('cnp').disable();
																							Ext.getCmp('persoana-fizica').collapse();															
																						}
																					}
																		}
																	}),{
											                    		fieldLabel	:'Nume',
											                    		name		:'nume',
																		anchor		:'90%',
																		allowBlank	:false,
																		blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>'
											                		},{
											                    		fieldLabel	:'Adresa',
											                    		name		:'adresa',
																		anchor		:'90%',
																		allowBlank	:false,
																		blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>'	
											                		},new Ext.form.ComboBox({
																			anchor		:'90%',	
																			fieldLabel	:'Judet',
																			name		:'n_judet', 
																			allowBlank	:false,
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
																			editable	:false,								
																			lazyRender	:true,
																			store		:new Ext.data.Store({
																						     id			:'judet_client_ds',
																							 baseParams	:{saferequest:true,code:'county'},
																						     proxy		:new Ext.data.HttpProxy({
																						     				url		:'common/getReference/' + Math.random()
																						 }),
																			 reader		: new Ext.data.JsonReader({
																									        root	:'DS_COUNTY',
																									        id		:'value',
																									        fields	:['value', 'option']
																				         })
																		}),
																		hiddenName		:'judet',
																		displayField	:'option',
																		valueField		:'value',									
																		triggerAction	:'all',
																		emptyText		:'[Selectati Judetul]'
																	}),{
											                    		fieldLabel	:'E-mail',
											                    		name		:'email',
																		anchor		:'90%'															
											                		},new Ext.form.ComboBox({
																			anchor		:'90%',	
																			fieldLabel	:'Platitor TVA?',
																			name		:'n_platitor_tva', 
																			allowBlank	:false, 
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
																			editable	:false,								
																			lazyRender	:true,
																			store		:new Ext.data.Store({
																						     id			:'platitor_tva_client_ds',
																							 baseParams	:{saferequest:true,code:'tva_payer'},
																						     proxy		:new Ext.data.HttpProxy({
																						     				url		:'common/getReference/' + Math.random()
																						 }),
																			 reader		: new Ext.data.JsonReader({
																									        root	:'DS_TVA_PAYER',
																									        id		:'value',
																									        fields	:['value', 'option']
																				         })
																		}),
																		hiddenName		:'platitor_tva',
																		displayField	:'option',
																		valueField		:'value',									
																		triggerAction	:'all',
																		emptyText		:'[Selectati]'
																	})
														]			
													},{
									                	columnWidth	:.5,
														defaultType	:'textfield',								
									                	layout		:'form',
									                	border		:false,
														items		:[new Ext.form.FieldSet({
																			id				:'persoana-fizica',
																			anchor			:'90%',
																            title			:'Persoana fizica',
																            autoHeight		:true,
																            collapsible		:true,
																            defaultType		:'textfield',
																			items			:[{
																								id			:'cnp',
																	                    		fieldLabel	:'CNP',
																	                    		name		:'cnp',
																								anchor		:'90%',
																								disabled	:true,
																								allowBlank	:false,																
																								blankText	:'Pentru statut client "Persoana fizica", acest camp este obligatoriu!'															
																			}]
																	}),new Ext.form.FieldSet({
																			id				:'persoana-juridica',		
																            title			:'Persoana juridica',
																			anchor			:'90%',
																            autoHeight		:true,
																            collapsible		:true,
																            defaultType		:'textfield',																
																			items			:[{
																								id				:'cui',
																	                    		fieldLabel		:'CUI',
																	                    		name			:'cui',
																								anchor			:'90%',
																								disabled		:true,
																								allowBlank		:false,	
																								blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'															
																							},{
																								id				:'nr_reg',
																	                    		fieldLabel		:'Nr. reg. com',
																	                    		name			:'nr_reg',
																								anchor			:'90%',
																								disabled		:true,
																								allowBlank		:false,	
																								blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																	                		},{
																								id				:'banca',
																	                    		fieldLabel		:'Banca',
																	                    		name			:'banca',
																								anchor			:'90%',
																								disabled		:true,
																								allowBlank		:false,	
																								blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																	                		},{
																								id				:'cont',	
																	                    		fieldLabel		:'Cont',
																	                    		name			:'cont',
																								anchor			:'90%',
																								disabled		:true,
																								allowBlank		:false,	
																								blankText		:'Pentru statut client "Persoana juridica", acest camp este obligatoriu!'	
																	       	}]
																		})
															]															
													}
											]
							}],
					        buttons: [{
										text	:'Save and Close',
					            		tooltip	:'Salvati si Inchideti',
										formBind:true,
										handler : function(){
													if (fp_w_user_introducere_factura_client.getForm().isValid()) {
														fp_w_user_introducere_factura_client.getForm().submit({
															url: "common/insertTable/" + Math.random(),
															params: {
																saferequest: true,
																table: 'clienti',
																cyDep: true
															},
															waitTitle: 'Connecting',
															waitMsg: 'Validating and saving data...',
															success: function(form, action, o){
																if (action.result.code == 0) {
																	Ext.MessageBox.alert('Atentie:', 'Eroare la adaugare');
																	fp_w_user_introducere_factura_client.getForm().reset();
																}
																else 
																	if (action.result.code == 1) {
																		Ext.MessageBox.alert('Mesaj:', 'Adaugare efectuata cu succes!');
																		ds_clienti.reload();
																		fp_w_user_introducere_factura_client.getForm().reset();
																		w_user_introducere_factura_client.hide();
																	}
															},
															failure: function(form, action, o){
																if (action.failureType == 'server') {
																	Ext.Msg.alert('Warning', 'Cannot save to database!', obj.errors.reason);
																}
																else {
																	Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
																}
																fp_w_user_introducere_factura_client.getForm().reset();
															}
														})
													}	
								  			}	
					        		},{
										text: 'Reset',
										tooltip:'Resetati',
										handler: function(){
											fp_w_user_introducere_factura_client.getForm().reset();
											Ext.getCmp('persoana-fizica').expand();		
											Ext.getCmp('persoana-juridica').expand();		
											
										}
									}]														
					});									
					
					// end adaugare client form panel	-------------------------------------------------
					//-----------------------------------------------------------------------------------	
														
						w_user_introducere_factura_client = new Ext.Window({
							id				:'w-user-introducere-client' + Math.random(),
							title			:'Adaugare client',
							animateTarget	:'b-add',
							width			:610,
							height			:450,
							plain			:true,
							layout			:'fit',
							modal			:true,
							closeAction		:'hide',
							items			:fp_w_user_introducere_factura_client,
							loadMask		:{msg:'Loading...'},
							listeners		:{
								show		:function(){
											fp_w_user_introducere_factura_client.getForm().reset();
											Ext.getCmp('persoana-fizica').expand();		
											Ext.getCmp('persoana-juridica').expand();	
											Ext.getCmp('cui').disable();
											Ext.getCmp('nr_reg').disable();		
											Ext.getCmp('banca').disable();
											Ext.getCmp('cont').disable();																																																					
											Ext.getCmp('cnp').disable();
								}
							},
				            buttons: [{
							    text		:'Cancel',
								tooltip		:'Renuntati',
							    handler		:function(){
									fp_w_user_introducere_factura_client.getForm().reset();
							        w_user_introducere_factura_client.hide();
							    }
							}]
					
						});								

		}else {}
		w_user_introducere_factura_client.show();	
	}	
		
		

/**
 * 
 * grid articole
 * 
 */

	
	cmb_produse = new Ext.form.ComboBox({
						id				:'produs',
						triggerAction	:'all',
						lazyRender		:true,
						store			:ds_produse,
						displayField	:'value',
						valueField		:'ID'				   					     	
	})		

	Ext.ux.renderer.Combo = function(combo) {
	    return function(value, meta, record) {
	        return Ext.ux.renderer.ComboRenderer({value: value, meta: meta, record: record, combo: combo});
	    };
	}
							
    cm_articole = new Ext.grid.ColumnModel([
			{
				id:'articole',
				header: "Articole",
				dataIndex: 'FK_PRODUSE',	
				editor:cmb_produse,
				renderer: Ext.ux.renderer.Combo(cmb_produse)	
			},{
			   header: "Cantitate",
			   dataIndex: 'cantitate',
			   editor: new Ext.form.NumberField({
			       allowBlank	: false,
			       allowNegative: false
			   })		   
			},{
			   header: "Pret unitar",
			   dataIndex: 'pret_unitar',
			   editor: new Ext.form.NumberField({
			       allowBlank	: false,
				   allowNegative: false
			   })
			}
    ]);
	
    var articole_new_record = Ext.data.Record.create([
           {name: 'FK_PRODUSE', type: 'int'},
           {name: 'cantitate', type: 'int'},
           {name: 'pret_unitar', type: 'int'}
      ]);
	  
	ds_articole = new Ext.data.Store({
						pruneModifiedRecords:true
	}); 
	
	/* Yet another store.json mode
	var arrData = [];
	var toJSON = function(record){
	  arrData.push (Ext.util.JSON.encode(record.data ));  //may need Field mapping here as well.
	};
	article_store.each(toJSON);
	jsonData = '[' + arrData.join(',') + ']';						
    */

	grid_user_introducere_factura_articole = new Ext.grid.EditorGridPanel({
		viewConfig			:{forceFit:true},
		plugins				:new Ext.ux.plugins.GridValidator(),			
		store				:ds_articole,
		cm					:cm_articole,
			title				:'Adaugare articole',
		frame				:false,
		clicksToEdit		:2,
		selModel			:new Ext.grid.RowSelectionModel({singleSelect:true}),
		stripeRows			:true,
		//forceValidation		:true,
		//ext grid listeners | keeped here because there is nothing in documentation
		/*	
		listeners			:{
			'validateedit'	:function(e){
				//alert(e.field+"="+e.value);
			},
			'afteredit'		:function(){
				
			},
			'add'			:function(){
				
			},
			'remove'		:function(){
				
			}							
		},
		*/
		tbar				:[{
			text: 'Add',
			tooltip: 'Adaugati',
			iconCls: 'b_add_xml_cls',
			handler: function(){
				var p = new articole_new_record({
					FK_PRODUSE: '',
					cantitate: '',
					pret_unitar: ''
				});
				grid_user_introducere_factura_articole.stopEditing();
				ds_articole.insert(0, p);
				grid_user_introducere_factura_articole.startEditing(0, 0);
			}
		},{
				            text	:'Delete',
							tooltip	:'Stergeti',
							iconCls	:'b_delete_xml_cls',
							handler	:function(){
								var selectionModel = grid_user_introducere_factura_articole.getSelectionModel();
								var selectedRow = selectionModel.getSelected();
								if (selectedRow) {
									Ext.MessageBox.confirm('Confirmation','Stergeti inregistrarea. Continuati?', function(btn){
										if (btn == 'yes') {
						                   	var selIdx = grid_user_introducere_factura_articole.store.indexOf(selectedRow);
											grid_user_introducere_factura_articole.getStore().remove(selectedRow);
											selectionModel.selectRow(selIdx);																
										}
									});
								}
							}
		}],
		bbar				:[{
				            text			:'Save',
							tooltip			:'Salvati lista de articole',
							iconCls			:'b_save_xml_cls',
							handler			:function(){
								Ext.MessageBox.confirm('Confirmation','Salvati lista de articole?', function(btn){
									if (btn == 'yes'){ 
										var json = '[';
										ds_articole.each(function(store){
										  json += Ext.util.JSON.encode(store.data) + ',';
										});
										json = json.substring(0, json.length - 1);
										json += ']'
										Ext.getDom('articole').value = json;	
									}
								})
							}							
			
		}]																

	});



/**
 * 
 * form panel
 */
    fp_user_introducere_factura = new Ext.FormPanel({
		id			:'frm-facturi-add',
		monitorValid:true,
        labelAlign	:'top',
        title		:'<?=$title?>',
		renderTo	:'user_introducere_factura',
        bodyStyle	:'padding:5px',
        items		:[{
            	layout	:'column',
            	border	:false,
            	items	:[{
                	columnWidth	:.5,
                	layout		:'form',
					defaultType	:'textfield',				
                	border		:false,
                	items		: [new Ext.form.ComboBox({
								anchor			:'90%',
								fieldLabel		:'Client',
								name			:'n_client',															
								allowBlank		:false, 
								blankText		:'Reguli validare <br /><i>Camp obligatoriu</i>',
								editable		:false,								
								lazyRender		:true,
								store			:ds_clienti,
								hiddenName		:'client',
								displayField	:'nume',
								valueField		:'ID',									
								triggerAction	:'all',
								emptyText		:'[Selectati Clientul]'
							})						
					]
            },{
                columnWidth	:.5,
                layout		:'form',
				defaultType	:'textfield',				
                border		:false,
                items		:[new Ext.Button({   
								id		:'b-add-client',
								text	:'Adauga client',
								style	:{ marginTop: '18px' },
								iconCls	:'b_add_cls',
								handler	:clienti_add
							}),
							{
								xtype		:'hidden',
	                    		fieldLabel	:'Articole',
								anchor		:'90%',
								id			:'articole',
	                    		name		:'articole',
								readOnly	:true,
								hideLabel	:true,
								style		:{ marginTop: '7px' },
								value		:0,
								blankText	:'Nu a fost inregistrat nici un articol pentru aceasta factura!',
								validateValue: function(){
									if (this.getValue().length < 40) {
										this.markInvalid(this.blankText);
										return false;
									}
									else {
										this.clearInvalid();
										return true;
									}
								}		 
                			}	
				]
            }]
        },{
            xtype		:'tabpanel',
            plain		:true,
            activeTab	:0,
            height		:320,
            items		:[{
                title		:'Date specifice',
                layout		:'form',
				bodyStyle	:'padding:10px',
       			items		:[{
            			layout	:'column',
            			border	:false,
						items	:[{
				                columnWidth	:.5,
				                layout		:'form',
				                border		:false,
				                defaultType	:'textfield',								
								items		:[
											new Ext.form.DateField({
												anchor		:'90%',
					                        	fieldLabel	:'Data emiterii',
					                        	name		:'data_emiterii',
					                        	allowBlank	:false,
												readOnly 	:true,
												invalidText :'{value} nu este o data valida - Formatul corect este: aaaa-ll-zz',
												blankText	:'Reguli validare <br /><i>Camp obligatoriu</i><br /><i>Format: aaaa-ll-zz</i>',
												format		:'Y-m-d'
                    						}),
											new Ext.form.DateField({
												anchor		:'90%',
					                        	fieldLabel	:'Data scadentei',
					                        	name		:'data_scadentei',
					                        	allowBlank	:false,
												readOnly 	:true,
												invalidText :'{value} nu este o data valida - Formatul corect este: aaaa-ll-zz',
												blankText	:'Reguli validare <br /><i>Camp obligatoriu</i><br /><i>Format: aaaa-ll-zz</i>',
												format		:'Y-m-d'												
                    				})
								]
						},{
				                columnWidth	:.5,
				                layout		:'form',
				                border		:false,
								defaultType	:'textfield',								
								items		:[
											new Ext.form.DateField({
												anchor		:'90%',
					                        	fieldLabel	:'Data expedierii',
					                        	name		:'data',
					                        	allowBlank	:false,
												readOnly 	:true,
												invalidText :'{value} nu este o data valida - Formatul corect este: aaaa-ll-zz',
												blankText	:'Reguli validare <br /><i>Camp obligatoriu</i><br /><i>Format: aaaa-ll-zz</i>',
												format		:'Y-m-d'                    						
												}),
											new Ext.form.ComboBox({
												anchor		:'90%',	
												fieldLabel	:'Moneda',
												name		:'n_moneda', 
												allowBlank	:false, 
												blankText		:'Reguli validare <br /><i>Camp obligatoriu</i>',
												editable	:false,								
												lazyRender	:true,
												store		:new Ext.data.Store({
															     id			:'moneda_ds',
																 baseParams	:{saferequest:true,code:'money'},
															     proxy		:new Ext.data.HttpProxy({
															     				url		:'common/getReference/' + Math.random()
															 }),
												 reader		: new Ext.data.JsonReader({
																		        root	:'DS_MONEY',
																		        id		:'value',
																		        fields	:['value', 'option']
													         })
											}),
											hiddenName		:'moneda',
											displayField	:'option',
											valueField		:'value',									
											triggerAction	:'all',
											emptyText		:'[Selectati Moneda]'
									})
								]
						}]		
				}]
            },{
                title		:'Expeditie',
                layout		:'form',
                bodyStyle	:'padding:10px',
                defaultType	:'textfield',					
	            items		:[
							new Ext.form.FieldSet({
								anchor		:'90%',
								title		:'Expediere',
								defaultType	:'textfield',
								autoHeight	:true,
								collapsible	:false,
								collapsed	:false,
								items		:[
											new Ext.form.ComboBox({
												anchor			:'90%',
												id				:'cu-auto',
												fieldLabel		:'Cu auto?',
												name			:'n_cu_auto', 
												allowBlank		:false,
												blankText		:'Reguli validare <br /><i>Camp obligatoriu</i>', 
												editable		:false,								
												lazyRender		:true,
												store			:new Ext.data.Store({
																    id			:'cu_auto_ds',
																	baseParams	:{saferequest:true,code:'auto'},
																    proxy		:new Ext.data.HttpProxy({
																					url		:'common/getReference/' + Math.random()
																     			}),
																	reader		:new Ext.data.JsonReader({
															            			root	:'DS_AUTO',
															            			id		:'value',
															            			fields	:['value', 'option']
															         			})
												}),
												listeners		:{
													'select'	:function(){
																	if (this.getRawValue() == 'DA'){		//if DA
																		Ext.getCmp('nr_auto').reset();
																		Ext.getCmp('nr_auto').enable();
																	}else if (this.getRawValue() == 'NU') {	//if NU
																		Ext.getCmp('nr_auto').reset();
																		Ext.getCmp('nr_auto').disable();
																	}
													}	
												},
												hiddenName		:'cu_auto',
												displayField	:'option',
												valueField		:'value',									
												triggerAction	:'all',
												emptyText		:'[ Selectati ]'
										}),{
											anchor			:'90%',
											id				:'nr_auto',
				                    		fieldLabel		:'Nr. auto',
				                    		name			:'nr_auto',
											disabled		:true,
											blankText		:'Reguli validare <br /><i>Camp obligatoriu</i>',
											allowBlank		:false 
				                		}								
								]
							}),
							new Ext.form.FieldSet({
								anchor		:'90%',
								title		:'Date delegat',
								defaultType	:'textfield',
								autoHeight	:true,
								collapsible	:false,
								collapsed	:false,
								items		:[{
											anchor		:'90%',	
				                    		fieldLabel	:'Nume si prenume',
											allowBlank	:false,
											blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
				                    		name		:'delegat'
										},{
											anchor		:'90%',	
				                    		fieldLabel	:'BI/CI [Serie si numar]',
											allowBlank	:false,
											blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',
				                    		name		:'delegat_ci'
										}
								]
							})
				]
            },{
                title		:'Detalii',
                layout		:'form',
                bodyStyle	:'padding:10px',
                defaultType	:'textfield',						
	            items		:[{
								anchor		:'90%',
	                    		fieldLabel	:'Numar contract',
	                    		name		:'nr_contract',
								allowBlank	:true
	                		},{
								anchor		:'90%',
	                    		fieldLabel	:'Detalii',
	                    		name		:'detalii',
								xtype		:'textarea',
								allowBlank	:true
	                		},new Ext.form.ComboBox({
								anchor			:'90%',
								fieldLabel		:'Tiparim stampila?',
								name			:'n_stampila', 
								allowBlank		:false,
								blankText		:'Reguli validare <br /><i>Camp obligatoriu</i>', 
								editable		:false,								
								lazyRender		:true,
								store			:new Ext.data.Store({
												     id			:'stampila_ds',
													 baseParams	:{saferequest:true,code:'stamp'},
												     proxy		:new Ext.data.HttpProxy({
												                	url		:'common/getReference/' + Math.random()
												     }),
													 reader		:new Ext.data.JsonReader({
											            			root	:'DS_STAMP',
											            			id		:'value',
											            			fields	:['value', 'option']
											         })
								}),
								hiddenName		:'stampila',
								displayField	:'option',
								valueField		:'value',									
								triggerAction	:'all',
								emptyText		:'[ Selectati ]'
							})]
            },{
                title		:'Articole',
                layout		:'fit',
                items		:[grid_user_introducere_factura_articole]
            }]
        }],
        buttons: [{
            text		:'Print preview',
			iconCls		:'b_preview_bill_cls',
			tooltip		:'Previzualizati',
			formBind	:true,
			handler		:function(){
				if (fp_user_introducere_factura.getForm().isValid()) {
					if (!w_user_introducere_factura_previzualizare) {
						w_user_introducere_factura_previzualizare = new Ext.Window({
							id			:'w-user-introducere-factura-previzualizare' + Math.random(),
			                width		:900,
							height		:480,
			                layout 		:'fit',
			                frame		:true,
							loadMask	:{msg:'Loading...'},
							waitMsg		:'Loading',
			                animCollapse:false,	
							modal		:true,
							closable	:true,
							closeAction	:'hide',						
							defaultType :'iframepanel',											
			                items:{ 
								title		:'Previzualizare factura',
								loadMask:{hideOnReady :false,msg:'Loading ...'},
								frameConfig	:{
									id:'previewIframe'
								}	                    
							},
							listeners:{
								show:function(){
									var json = Ext.util.JSON.encode(fp_user_introducere_factura.form.getValues(false));	
									Ext.get('previewIframe').load({
										url: 'user/functionalitati/previzualizare/' + Math.random(),
										method:'post',
										params	:{
												saferequest	:true,
												DATA_DS		:json
										}									
									});
								}
							}
						});								
					}else {}
					w_user_introducere_factura_previzualizare.show();	
				}
			}			
        },{
            text		:'Print',
			iconCls		:'b_print_bill_cls',
			tooltip		:'Tipariti',
			formBind	:true,
			handler		:function(){
				if (fp_user_introducere_factura.getForm().isValid()) {
					if (!w_user_introducere_factura_tiparire) {
						w_user_introducere_factura_tiparire = new Ext.Window({
							id			:'w-user-introducere-factura-tiparire' + Math.random(),
			                width		:900,
							height		:480,
			                layout 		:'fit',
			                frame		:true,
							loadMask	:{msg:'Loading...'},
							waitMsg		:'Loading',
			                animCollapse:false,	
							modal		:true,
							closable	:true,
							closeAction	:'hide',						
							defaultType :'iframepanel',											
			                items:{ 
								title		:'Tiparire factura',
								loadMask:{hideOnReady :false,msg:'Loading ...'},
								frameConfig	:{
									id:'printIframe'
								},
								listeners	:{
									documentloaded: function(frame){
												fp_user_introducere_factura.getForm().submit({
											  		url: "user/functionalitati/salvare/" + Math.random(),
													params:{saferequest:true,table:'facturi'},
											  		waitTitle: 'Connecting',
											  		waitMsg: 'Validating and saving data...',										
													success:function(form, action, o) {
														if(action.result.code == 0){
																Ext.MessageBox.alert('Atentie:', 'Eroare la adaugare');
														}else if(action.result.code == 1){
																frame.print();
																Ext.MessageBox.alert('Mesaj:', 'Adaugare efectuata cu succes!',function(){
																		w_user_introducere_factura_tiparire.hide();
																		fp_user_introducere_factura.getForm().reset();
																		//goHome();											
																});								
								
														}else if(action.result.code == 2){
																Ext.MessageBox.alert('Eroare la adaugare:', 'Tranzactie nereusita!');
														}else if(action.result.code == 3){
																Ext.MessageBox.alert('Eroare la adaugare:', 'Adaugare factura nereusita!');
														}else if(action.result.code == 4){
																Ext.MessageBox.alert('Eroare la adaugare:', 'Adaugare articole nereusita!');
														}else if(action.result.code == 5){
																Ext.MessageBox.alert('Eroare la adaugare:', 'Actualizare numar curent factura nereusita!');
														}
													},										
													failure: function(form, action, o){
									                            if(action.failureType == 'server'){
									                                Ext.Msg.alert('Warning', 'Cannot save to database!', obj.errors.reason);
									                            }else{
									                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
									                            }
													}
										  	})																
									}									
								}	                    
							},
							listeners:{
								show:function(){
									var json = Ext.util.JSON.encode(fp_user_introducere_factura.form.getValues(false));	
									Ext.get('printIframe').load({
										url: 'user/functionalitati/previzualizare/' + Math.random(),
										method:'post',
										params	:{
												saferequest	:true,
												DATA_DS		:json
										}
									});
								}									
							}
						});								
					}else {}
					w_user_introducere_factura_tiparire.show();	
				}			
			}
        },{
            text: 'Cancel',
			tooltip	:'Renuntati',
			iconCls	:'b_return_cls',	
			handler : function(){
				fp_user_introducere_factura.getForm().reset();
				goHome();
			}
        }]
    });	
});	
</script>